﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Cinema.Control;
using System.Threading;

namespace Cinema.GUI
{
    public partial class MainFrame : Form
    {
        public MainFrame()
        {
            InitializeComponent();
            foreach (System.Windows.Forms.Button confirmButton in confirmButtons)
            {
                confirmButton.Enabled = false;
            }
        }

        public void init()
        {
            SetVisibleCore(true);
        }

        private void MainFrame_Load(object sender, EventArgs e)
        {

        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void confirmButton_Click(object sender, EventArgs e)
        {
            foreach(DataGridViewRow row in saloonViews[saloonTabControl.SelectedIndex].Rows)
            {
                if (row.Cells[1].Value != null)
                {
                    Console.WriteLine("Seat " + row.Index + " TAKEN");
                }
                else
                {
                    Console.WriteLine("Seat " + row.Index + " FREE");
                }
            }
            
        }

        public void okButton_Click(object sender, EventArgs e)
        {
            int index = 0;
            while (index < 3)
            { 
                Boolean enabled = MainClass.logged;
                if (enabled)
                {
                    foreach (System.Windows.Forms.Button confirmButton in confirmButtons)
                    {
                        if (confirmButton.InvokeRequired)
                        {
                            setEnabledD d = new setEnabledD(this.setEnabled);
                            this.Invoke(d, new object[] { enabled, confirmButton });
                        }
                        else
                        {
                            confirmButton.Enabled = true;
                        }
                    }
                }
                else
                {
                    index++;
                    Thread.Sleep(1000);
                }
            }
        }

        delegate void setEnabledD(Boolean enabled, System.Windows.Forms.Button confirmButton);

        public void setEnabled(Boolean enabled, System.Windows.Forms.Button confirmButton)
        {
            confirmButton.Enabled = enabled;
        }

        public MainFrame getInstance()
        {
            return this;
        }
    }
}
